/*
 * * Copyright 1987-2022 ANSYS, Inc. All Rights Reserved.
 */

/* Maximum number of isosurface facets created in one cell */
#define MAX_ISO_FACETS 10

/* Maximum number of points per iso-facet (3D facets are tris or quads) */
#define MAX_FACET_PTS   4

/* Each one of these structs indicates how to create the iso-facets
   for a given arrangement of values on the vertices of a cell. A
   bit mask is constructed such that for each vertex with a value
   greater than the isovalue, the corresponding bit is set. For
   example, if no vertex values were greater than the isovalue, the
   bitmask would be zero. If all vertex values were greater than the
   isovalue, the bitmask would be all ones. If the only value greater
   than the isovalue was at vertex 1 (vertices numbered from zero)
   of an 8 node hex cell, the bitmask would be 00000010 or 2 decimal.
   Vertex 0 is the lowest order bit in the bitmask.
   This bitmask is used to index into a table of tab_structs, which
   describe how many facets will be created and which edges of the cell
   are intersected to create each facet.
   Hex node numbering is: nodes 0,1,2,3 are on a face such that right
   hand normal points outward, nodes 4,5,6,7 are on the opposite face,
   with an edge between corresponding nodes (0,4), (1,5), etc. See
   edge table in cxisosurf.c for edge numbering.
*/

typedef struct tab_struct
{
  unsigned char nfacets;  /* Number of facets for this arrangement */
  unsigned char facet[MAX_ISO_FACETS][MAX_FACET_PTS];
} CELL_ENTRY;


/* Note: Edges, vertices in the cell_table are numbered starting from 1.*/

/* Quad facets are used in the simple cases (eg, where 4 parallel edges
 * are intersected). This makes isosurfaces through hex grids look nicer
 * (quad mesh isosurface) when the grid is fairly orthogonal and the
 * isovariable is nicely behaved.
 */

static CELL_ENTRY hex_table[256] =
{
  /* 00000000 */
  { 0 },
  /* 00000001 */
  { 1, { { 1, 4, 9 } } },
  /* 00000010 */
  { 1, { { 1, 10, 2 } } },
  /* 00000011 */
  { 1, { { 2, 4, 9, 10 } } },
  /* 00000100 */
  { 1, { { 3, 2, 12 } } },
  /* 00000101 */
  { 2, { { 1, 4, 9 }, { 3, 2, 12 } } },
  /* 00000110 */
  { 1, { { 10, 12, 3, 1 } } },
  /* 00000111 */
  { 3, { { 12, 9, 10 }, { 3, 9, 12 }, { 3, 4, 9 } } },
  /* 00001000 */
  { 1, { { 3, 11, 4 } } },
  /* 00001001 */
  { 1, { { 11, 9, 1, 3 } } },
  /* 00001010 */
  { 2, { { 2, 1, 10 }, { 4, 3, 11 } } },
  /* 00001011 */
  { 3, { { 10, 11, 9 }, { 2, 11, 10 }, { 2, 3, 11 } } },
  /* 00001100 */
  { 1, { { 12, 11, 4, 2 } } },
  /* 00001101 */
  { 3, { { 9, 12, 11 }, { 1, 12, 9 }, { 1, 2, 12 } } },
  /* 00001110 */
  { 3, { { 11, 10, 12 }, { 4, 10, 11 }, { 4, 1, 10 } } },
  /* 00001111 */
  { 1, { { 11, 9, 10, 12 } } },
  /* 00010000 */
  { 1, { { 5, 9, 8 } } },
  /* 00010001 */
  { 1, { { 4, 8, 5, 1 } } },
  /* 00010010 */
  { 2, { { 5, 9, 8 }, { 1, 10, 2 } } },
  /* 00010011 */
  { 3, { { 8, 2, 4 }, { 5, 2, 8 }, { 5, 10, 2 } } },
  /* 00010100 */
  { 2, { { 5, 9, 8 }, { 12, 3, 2 } } },
  /* 00010101 */
  { 3, { { 2, 12, 3 }, { 4, 8, 5 }, { 4, 5, 1 } } },
  /* 00010110 */
  { 3, { { 9, 8, 5 }, { 10, 12, 3 }, { 10, 3, 1 } } },
  /* 00010111 */
  { 4, { { 3, 10, 12 }, { 3, 8, 10 }, { 3, 4, 8 }, { 10, 8, 5 } } },
  /* 00011000 */
  { 2, { { 9, 8, 5 }, { 11, 4, 3 } } },
  /* 00011001 */
  { 3, { { 3, 5, 1 }, { 11, 5, 3 }, { 11, 8, 5 } } },
  /* 00011010 */
  { 3, { { 10, 2, 1 }, { 4, 3, 11 }, { 9, 8, 5 } } },
  /* 00011011 */
  { 4, { { 10, 2, 3 }, { 5, 10, 3 }, { 11, 5, 3 }, { 8, 5, 11 } } },
  /* 00011100 */
  { 2, { { 8, 5, 9 }, { 4, 2, 12, 11 } } },
  /* 00011101 */
  { 4, { { 12, 11, 2 }, { 11, 5, 2 }, { 5, 1, 2 }, { 8, 5, 11 } } },
  /* 00011110 */
  { 4, { { 11, 10, 12 }, { 11, 1, 10 }, { 4, 1, 11 }, { 8, 5, 9 } } },
  /* 00011111 */
  { 3, { { 11, 10, 12 }, { 11, 5, 10 }, { 8, 5, 11 } } },
  /* 00100000 */
  { 1, { { 5, 6, 10 } } },
  /* 00100001 */
  { 2, { { 10, 5, 6 }, { 9, 1, 4 } } },
  /* 00100010 */
  { 1, { { 6, 2, 1, 5 } } },
  /* 00100011 */
  { 3, { { 4, 6, 2 }, { 9, 6, 4 }, { 9, 5, 6 } } },
  /* 00100100 */
  { 2, { { 2, 12, 3 }, { 6, 10, 5 } } },
  /* 00100101 */
  { 3, { { 12, 3, 2 }, { 1, 4, 9 }, { 10, 5, 6 } } },
  /* 00100110 */
  { 3, { { 5, 3, 1 }, { 6, 3, 5 }, { 6, 12, 3 } } },
  /* 00100111 */
  { 4, { { 12, 3, 4 }, { 6, 12, 4 }, { 9, 6, 4 }, { 5, 6, 9 } } },
  /* 00101000 */
  { 2, { { 3, 11, 4 }, { 10, 5, 6 } } },
  /* 00101001 */
  { 2, { { 5, 6, 10 }, { 1, 3, 11, 9 } } },
  /* 00101010 */
  { 2, { { 3, 11, 4 }, { 1, 5, 6, 2 } } },
  /* 00101011 */
  { 4, { { 11, 9, 3 }, { 9, 6, 3 }, { 6, 2, 3 }, { 5, 6, 9 } } },
  /* 00101100 */
  { 2, { { 10, 5, 6 }, { 12, 11, 4, 2 } } },
  /* 00101101 */
  { 4, { { 9, 12, 11 }, { 9, 2, 12 }, { 1, 2, 9 }, { 5, 6, 10 } } },
  /* 00101110 */
  { 4, { { 4, 12, 11 }, { 4, 5, 12 }, { 4, 1, 5 }, { 12, 5, 6 } } },
  /* 00101111 */
  { 3, { { 9, 12, 11 }, { 9, 6, 12 }, { 5, 6, 9 } } },
  /* 00110000 */
  { 1, { { 10, 9, 8, 6 } } },
  /* 00110001 */
  { 3, { { 6, 4, 8 }, { 10, 4, 6 }, { 10, 1, 4 } } },
  /* 00110010 */
  { 3, { { 2, 8, 6 }, { 1, 8, 2 }, { 1, 9, 8 } } },
  /* 00110011 */
  { 1, { { 4, 8, 6, 2 } } },
  /* 00110100 */
  { 3, { { 12, 3, 2 }, { 10, 9, 8 }, { 10, 8, 6 } } },
  /* 00110101 */
  { 4, { { 6, 4, 8 }, { 6, 1, 4 }, { 10, 1, 6 }, { 12, 3, 2 } } },
  /* 00110110 */
  { 4, { { 8, 6, 9 }, { 6, 3, 9 }, { 3, 1, 9 }, { 12, 3, 6 } } },
  /* 00110111 */
  { 3, { { 6, 4, 8 }, { 6, 3, 4 }, { 12, 3, 6 } } },
  /* 00111000 */
  { 3, { { 4, 3, 11 }, { 8, 6, 10 }, { 8, 10, 9 } } },
  /* 00111001 */
  { 4, { { 10, 8, 6 }, { 10, 3, 8 }, { 10, 1, 3 }, { 8, 3, 11 } } },
  /* 00111010 */
  { 4, { { 2, 8, 6 }, { 2, 9, 8 }, { 1, 9, 2 }, { 3, 11, 4 } } },
  /* 00111011 */
  { 3, { { 2, 8, 6 }, { 2, 11, 8 }, { 3, 11, 2 } } },
  /* 00111100 */
  { 2, { { 11, 4, 2, 12 }, { 10, 9, 8, 6 } } },
  /* 00111101 */
  { 5, { { 1, 2, 10 }, { 8, 6, 11 }, { 11, 6, 12 }, { 12, 6, 2 }, { 2, 6, 10 } } },
  /* 00111110 */
  { 5, { { 1, 9, 4 }, { 12, 11, 6 }, { 6, 11, 8 }, { 8, 11, 9 }, { 9, 11, 4 } } },
  /* 00111111 */
  { 1, { { 11, 8, 6, 12 } } },
  /* 01000000 (64) */
  { 1, { { 7, 12, 6 } } },
  /* 01000001 */
  { 2, { { 1, 4, 9 }, { 6, 7, 12 } } },
  /* 01000010 */
  { 2, { { 10, 2, 1 }, { 12, 6, 7 } } },
  /* 01000011 */
  { 2, { { 6, 7, 12 }, { 2, 4, 9, 10 } } },
  /* 01000100 */
  { 1, { { 2, 6, 7, 3 } } },
  /* 01000101 */
  { 2, { { 4, 9, 1 }, { 2, 6, 7, 3 } } },
  /* 01000110 */
  { 3, { { 1, 7, 3 }, { 10, 7, 1 }, { 10, 6, 7 } } },
  /* 01000111 */
  { 4, { { 9, 10, 4 }, { 10, 7, 4 }, { 7, 3, 4 }, { 6, 7, 10 } } },
  /* 01001000 */
  { 2, { { 3, 11, 4 }, { 7, 12, 6 } } },
  /* 01001001 */
  { 2, { { 12, 6, 7 }, { 11, 9, 1, 3 } } },
  /* 01001010 */
  { 3, { { 6, 7, 12 }, { 3, 11, 4 }, { 2, 1, 10 } } },
  /* 01001011 */
  { 4, { { 10, 11, 9 }, { 10, 3, 11 }, { 2, 3, 10 }, { 6, 7, 12 } } },
  /* 01001100 */
  { 3, { { 6, 4, 2 }, { 7, 4, 6 }, { 7, 11, 4 } } },
  /* 01001101 */
  { 4, { { 7, 2, 6 }, { 7, 9, 2 }, { 7, 11, 9 }, { 2, 9, 1 } } },
  /* 01001110 */
  { 4, { { 6, 7, 11 }, { 10, 6, 11 }, { 4, 10, 11 }, { 1, 10, 4 } } },
  /* 01001111 */
  { 3, { { 10, 11, 9 }, { 10, 7, 11 }, { 6, 7, 10 } } },
  /* 01010000 */
  { 2, { { 6, 7, 12 }, { 8, 5, 9 } } },
  /* 01010001 */
  { 2, { { 7, 12, 6 }, { 5, 1, 4, 8 } } },
  /* 01010010 */
  { 3, { { 2, 1, 10 }, { 5, 9, 8 }, { 6, 7, 12 } } },
  /* 01010011 */
  { 4, { { 8, 2, 4 }, { 8, 10, 2 }, { 5, 10, 8 }, { 7, 12, 6 } } },
  /* 01010100 */
  { 2, { { 5, 9, 8 }, { 7, 3, 2, 6 } } },
  /* 01010101 */
  { 4, { { 5, 1, 8 }, { 1, 4, 8 }, { 7, 2, 6 }, { 7, 3, 2 } } },
  /* 01010110 */
  { 4, { { 1, 7, 3 }, { 1, 6, 7 }, { 10, 6, 1 }, { 9, 8, 5 } } },
  /* 01010111 */
  { 5, { { 10, 6, 5 }, { 4, 8, 3 }, { 3, 8, 7 }, { 7, 8, 6 }, { 6, 8, 5 } } },
  /* 01011000 */
  { 3, { { 12, 6, 7 }, { 8, 5, 9 }, { 11, 4, 3 } } },
  /* 01011001 */
  { 4, { { 3, 5, 1 }, { 3, 8, 5 }, { 11, 8, 3 }, { 12, 6, 7 } } },
  /* 01011010 */
  { 4, { { 3, 11, 4 }, { 12, 6, 7 }, { 1, 10, 2 }, { 5, 9, 8 } } },
  /* 01011011 */
  { 10, { { 5, 10, 6 }, { 8, 7, 11 }, { 3, 12, 2 }, { 12, 3, 11 }, { 12, 11, 7 }, { 7, 8, 5 }, { 7, 5, 6 }, { 12, 10, 2 }, { 12, 6, 10 }, { 12, 7, 6 } } },
  /* 01011100 */
  { 4, { { 6, 4, 2 }, { 6, 11, 4 }, { 7, 11, 6 }, { 5, 9, 8 } } },
  /* 01011101 */
  { 5, { { 11, 8, 7 }, { 2, 6, 1 }, { 1, 6, 5 }, { 5, 6, 8 }, { 8, 6, 7 } } },
  /* 01011110 */
  { 10, { { 10, 6, 5 }, { 1, 9, 4 }, { 11, 8, 7 }, { 8, 11, 4 }, { 8, 4, 9 }, { 9, 1, 10 }, { 9, 10, 5 }, { 8, 6, 7 }, { 8, 5, 6 }, { 8, 9, 5 } } },
  /* 01011111 */
  { 4, { { 8, 7, 11 }, { 6, 5, 10 }, { 6, 7, 8 }, { 6, 8, 5 } } },
  /* 01100000 */
  { 1, { { 12, 10, 5, 7 } } },
  /* 01100001 */
  { 2, { { 1, 4, 9 }, { 5, 7, 12, 10 } } },
  /* 01100010 */
  { 3, { { 7, 1, 5 }, { 12, 1, 7 }, { 12, 2, 1 } } },
  /* 01100011 */
  { 4, { { 9, 2, 4 }, { 9, 7, 2 }, { 9, 5, 7 }, { 2, 7, 12 } } },
  /* 01100100 */
  { 3, { { 3, 5, 7 }, { 2, 5, 3 }, { 2, 10, 5 } } },
  /* 01100101 */
  { 4, { { 3, 5, 7 }, { 3, 10, 5 }, { 2, 10, 3 }, { 4, 9, 1 } } },
  /* 01100110 */
  { 1, { { 1, 5, 7, 3 } } },
  /* 01100111 */
  { 3, { { 3, 5, 7 }, { 3, 9, 5 }, { 4, 9, 3 } } },
  /* 01101000 */
  { 2, { { 11, 4, 3 }, { 12, 10, 5, 7 } } },
  /* 01101001 */
  { 2, { { 3, 11, 9, 1 }, { 5, 7, 12, 10 } } },
  /* 01101010 */
  { 4, { { 7, 1, 5 }, { 7, 2, 1 }, { 12, 2, 7 }, { 11, 4, 3 } } },
  /* 01101011 */
  { 5, { { 2, 3, 12 }, { 5, 7, 9 }, { 9, 7, 11 }, { 11, 7, 3 }, { 3, 7, 12 } } },
  /* 01101100 */
  { 4, { { 4, 2, 11 }, { 2, 5, 11 }, { 5, 7, 11 }, { 10, 5, 2 } } },
  /* 01101101 */
  { 5, { { 2, 10, 1 }, { 11, 9, 7 }, { 7, 9, 5 }, { 5, 9, 10 }, { 10, 9, 1 } } },
  /* 01101110 */
  { 3, { { 7, 1, 5 }, { 7, 4, 1 }, { 11, 4, 7 } } },
  /* 01101111 */
  { 1, { { 7, 11, 9, 5 } } },
  /* 01110000 */
  { 3, { { 9, 12, 10 }, { 8, 12, 9 }, { 8, 7, 12 } } },
  /* 01110001 */
  { 4, { { 4, 8, 1 }, { 8, 12, 1 }, { 12, 10, 1 }, { 7, 12, 8 } } },
  /* 01110010 */
  { 4, { { 2, 1, 9 }, { 12, 2, 9 }, { 8, 12, 9 }, { 7, 12, 8 } } },
  /* 01110011 */
  { 3, { { 8, 2, 4 }, { 8, 12, 2 }, { 7, 12, 8 } } },
  /* 01110100 */
  { 4, { { 8, 10, 9 }, { 8, 3, 10 }, { 8, 7, 3 }, { 10, 3, 2 } } },
  /* 01110101 */
  { 5, { { 10, 1, 2 }, { 7, 3, 8 }, { 8, 3, 4 }, { 4, 3, 1 }, { 1, 3, 2 } } },
  /* 01110110 */
  { 3, { { 1, 7, 3 }, { 1, 8, 7 }, { 9, 8, 1 } } },
  /* 01110111 */
  { 1, { { 4, 8, 7, 3 } } },
  /* 01111000 */
  { 4, { { 9, 12, 10 }, { 9, 7, 12 }, { 8, 7, 9 }, { 4, 3, 11 } } },
  /* 01111001 */
  { 5, { { 8, 7, 11 }, { 1, 3, 10 }, { 10, 3, 12 }, { 12, 3, 7 }, { 7, 3, 11 } } },
  /* 01111010 */
  { 10, { { 12, 2, 3 }, { 7, 11, 8 }, { 9, 4, 1 }, { 4, 9, 8 }, { 4, 8, 11 }, { 11, 7, 12 }, { 11, 12, 3 }, { 4, 2, 1 }, { 4, 3, 2 }, { 4, 11, 3 } } },
  /* 01111011 */
  { 4, { { 3, 12, 2 }, { 7, 11, 8 }, { 7, 12, 3 }, { 7, 3, 11 } } },
  /* 01111100 */
  { 5, { { 7, 11, 8 }, { 10, 9, 2 }, { 2, 9, 4 }, { 4, 9, 11 }, { 11, 9, 8 } } },
  /* 01111101 */
  { 2, { { 8, 7, 11 }, { 1, 2, 10 } } },
  /* 01111110 */
  { 4, { { 9, 4, 1 }, { 11, 8, 7 }, { 11, 4, 9 }, { 11, 9, 8 } } },
  /* 01111111 */
  { 1, { { 8, 7, 11 } } },
  /* 10000000 (128) */
  { 1, { { 7, 8, 11 } } },
  /* 10000001 */
  { 2, { { 4, 9, 1 }, { 8, 11, 7 } } },
  /* 10000010 */
  { 2, { { 7, 8, 11 }, { 2, 1, 10 } } },
  /* 10000011 */
  { 2, { { 11, 7, 8 }, { 9, 10, 2, 4 } } },
  /* 10000100 */
  { 2, { { 12, 3, 2 }, { 11, 7, 8 } } },
  /* 10000101 */
  { 3, { { 2, 12, 3 }, { 11, 7, 8 }, { 4, 9, 1 } } },
  /* 10000110 */
  { 2, { { 7, 8, 11 }, { 3, 1, 10, 12 } } },
  /* 10000111 */
  { 4, { { 12, 9, 10 }, { 12, 4, 9 }, { 3, 4, 12 }, { 7, 8, 11 } } },
  /* 10001000 */
  { 1, { { 8, 4, 3, 7 } } },
  /* 10001001 */
  { 3, { { 7, 1, 3 }, { 8, 1, 7 }, { 8, 9, 1 } } },
  /* 10001010 */
  { 2, { { 1, 10, 2 }, { 3, 7, 8, 4 } } },
  /* 10001011 */
  { 4, { { 2, 9, 10 }, { 2, 7, 9 }, { 2, 3, 7 }, { 9, 7, 8 } } },
  /* 10001100 */
  { 3, { { 2, 8, 4 }, { 12, 8, 2 }, { 12, 7, 8 } } },
  /* 10001101 */
  { 4, { { 2, 12, 7 }, { 1, 2, 7 }, { 8, 1, 7 }, { 9, 1, 8 } } },
  /* 10001110 */
  { 4, { { 8, 4, 7 }, { 4, 10, 7 }, { 10, 12, 7 }, { 1, 10, 4 } } },
  /* 10001111 */
  { 3, { { 12, 9, 10 }, { 12, 8, 9 }, { 7, 8, 12 } } },
  /* 10010000 */
  { 1, { { 9, 11, 7, 5 } } },
  /* 10010001 */
  { 3, { { 1, 7, 5 }, { 4, 7, 1 }, { 4, 11, 7 } } },
  /* 10010010 */
  { 2, { { 10, 2, 1 }, { 9, 11, 7, 5 } } },
  /* 10010011 */
  { 4, { { 2, 4, 10 }, { 4, 7, 10 }, { 7, 5, 10 }, { 11, 7, 4 } } },
  /* 10010100 */
  { 3, { { 3, 2, 12 }, { 7, 5, 9 }, { 7, 9, 11 } } },
  /* 10010101 */
  { 4, { { 1, 7, 5 }, { 1, 11, 7 }, { 4, 11, 1 }, { 2, 12, 3 } } },
  /* 10010110 */
  { 2, { { 7, 5, 9, 11 }, { 3, 1, 10, 12 } } },
  /* 10010111 */
  { 5, { { 4, 11, 3 }, { 10, 12, 5 }, { 5, 12, 7 }, { 7, 12, 11 }, { 11, 12, 3 } } },
  /* 10011000 */
  { 3, { { 5, 3, 7 }, { 9, 3, 5 }, { 9, 4, 3 } } },
  /* 10011001 */
  { 1, { { 5, 1, 3, 7 } } },
  /* 10011010 */
  { 4, { { 5, 3, 7 }, { 5, 4, 3 }, { 9, 4, 5 }, { 10, 2, 1 } } },
  /* 10011011 */
  { 3, { { 5, 3, 7 }, { 5, 2, 3 }, { 10, 2, 5 } } },
  /* 10011100 */
  { 4, { { 12, 4, 2 }, { 12, 5, 4 }, { 12, 7, 5 }, { 4, 5, 9 } } },
  /* 10011101 */
  { 3, { { 1, 7, 5 }, { 1, 12, 7 }, { 2, 12, 1 } } },
  /* 10011110 */
  { 5, { { 4, 1, 9 }, { 7, 5, 12 }, { 12, 5, 10 }, { 10, 5, 1 }, { 1, 5, 9 } } },
  /* 10011111 */
  { 1, { { 5, 10, 12, 7 } } },
  /* 10100000 */
  { 2, { { 7, 8, 11 }, { 5, 6, 10 } } },
  /* 10100001 */
  { 3, { { 6, 10, 5 }, { 9, 1, 4 }, { 8, 11, 7 } } },
  /* 10100010 */
  { 2, { { 8, 11, 7 }, { 6, 2, 1, 5 } } },
  /* 10100011 */
  { 4, { { 4, 6, 2 }, { 4, 5, 6 }, { 9, 5, 4 }, { 11, 7, 8 } } },
  /* 10100100 */
  { 3, { { 10, 5, 6 }, { 7, 8, 11 }, { 12, 3, 2 } } },
  /* 10100101 */
  { 4, { { 1, 4, 9 }, { 2, 12, 3 }, { 5, 6, 10 }, { 7, 8, 11 } } },
  /* 10100110 */
  { 4, { { 5, 3, 1 }, { 5, 12, 3 }, { 6, 12, 5 }, { 8, 11, 7 } } },
  /* 10100111 */
  { 10, { { 6, 12, 7 }, { 5, 8, 9 }, { 4, 11, 3 }, { 11, 4, 9 }, { 11, 9, 8 }, { 8, 5, 6 }, { 8, 6, 7 }, { 11, 12, 3 }, { 11, 7, 12 }, { 11, 8, 7 } } },
  /* 10101000 */
  { 2, { { 6, 10, 5 }, { 8, 4, 3, 7 } } },
  /* 10101001 */
  { 4, { { 7, 1, 3 }, { 7, 9, 1 }, { 8, 9, 7 }, { 6, 10, 5 } } },
  /* 10101010 */
  { 2, { { 3, 7, 8, 4 }, { 1, 5, 6, 2 } } },
  /* 10101011 */
  { 5, { { 9, 5, 8 }, { 3, 7, 2 }, { 2, 7, 6 }, { 6, 7, 5 }, { 5, 7, 8 } } },
  /* 10101100 */
  { 4, { { 2, 8, 4 }, { 2, 7, 8 }, { 12, 7, 2 }, { 10, 5, 6 } } },
  /* 10101101 */
  { 10, { { 1, 2, 10 }, { 9, 5, 8 }, { 7, 6, 12 }, { 6, 7, 8 }, { 6, 8, 5 }, { 5, 9, 1 }, { 5, 1, 10 }, { 6, 2, 12 }, { 6, 10, 2 }, { 6, 5, 10 } } },
  /* 10101110 */
  { 5, { { 12, 7, 6 }, { 1, 5, 4 }, { 4, 5, 8 }, { 8, 5, 7 }, { 7, 5, 6 } } },
  /* 10101111 */
  { 4, { { 7, 6, 12 }, { 5, 8, 9 }, { 5, 6, 7 }, { 5, 7, 8 } } },
  /* 10110000 */
  { 3, { { 11, 10, 9 }, { 7, 10, 11 }, { 7, 6, 10 } } },
  /* 10110001 */
  { 4, { { 6, 10, 1 }, { 7, 6, 1 }, { 4, 7, 1 }, { 11, 7, 4 } } },
  /* 10110010 */
  { 4, { { 1, 6, 2 }, { 1, 11, 6 }, { 1, 9, 11 }, { 6, 11, 7 } } },
  /* 10110011 */
  { 3, { { 4, 6, 2 }, { 4, 7, 6 }, { 11, 7, 4 } } },
  /* 10110100 */
  { 4, { { 11, 10, 9 }, { 11, 6, 10 }, { 7, 6, 11 }, { 3, 2, 12 } } },
  /* 10110101 */
  { 10, { { 7, 6, 12 }, { 11, 3, 4 }, { 1, 2, 10 }, { 2, 1, 4 }, { 2, 4, 3 }, { 3, 11, 7 }, { 3, 7, 12 }, { 2, 6, 10 }, { 2, 12, 6 }, { 2, 3, 12 } } },
  /* 10110110 */
  { 5, { { 6, 12, 7 }, { 9, 11, 1 }, { 1, 11, 3 }, { 3, 11, 12 }, { 12, 11, 7 } } },
  /* 10110111 */
  { 4, { { 11, 3, 4 }, { 12, 7, 6 }, { 12, 3, 11 }, { 12, 11, 7 } } },
  /* 10111000 */
  { 4, { { 10, 9, 6 }, { 9, 3, 6 }, { 3, 7, 6 }, { 4, 3, 9 } } },
  /* 10111001 */
  { 3, { { 7, 1, 3 }, { 7, 10, 1 }, { 6, 10, 7 } } },
  /* 10111010 */
  { 5, { { 9, 4, 1 }, { 6, 2, 7 }, { 7, 2, 3 }, { 3, 2, 4 }, { 4, 2, 1 } } },
  /* 10111011 */
  { 1, { { 7, 6, 2, 3 } } },
  /* 10111100 */
  { 5, { { 7, 6, 12 }, { 4, 2, 9 }, { 9, 2, 10 }, { 10, 2, 6 }, { 6, 2, 12 } } },
  /* 10111101 */
  { 4, { { 2, 10, 1 }, { 6, 12, 7 }, { 6, 10, 2 }, { 6, 2, 12 } } },
  /* 10111110 */
  { 2, { { 4, 1, 9 }, { 7, 6, 12 } } },
  /* 10111111 */
  { 1, { { 12, 7, 6 } } },
  /* 11000000 */
  { 1, { { 6, 8, 11, 12 } } },
  /* 11000001 */
  { 2, { { 9, 1, 4 }, { 11, 12, 6, 8 } } },
  /* 11000010 */
  { 2, { { 2, 1, 10 }, { 6, 8, 11, 12 } } },
  /* 11000011 */
  { 2, { { 2, 4, 9, 10 }, { 6, 8, 11, 12 } } },
  /* 11000100 */
  { 3, { { 8, 2, 6 }, { 11, 2, 8 }, { 11, 3, 2 } } },
  /* 11000101 */
  { 4, { { 8, 2, 6 }, { 8, 3, 2 }, { 11, 3, 8 }, { 9, 1, 4 } } },
  /* 11000110 */
  { 4, { { 11, 6, 8 }, { 11, 1, 6 }, { 11, 3, 1 }, { 6, 1, 10 } } },
  /* 11000111 */
  { 5, { { 3, 4, 11 }, { 6, 8, 10 }, { 10, 8, 9 }, { 9, 8, 4 }, { 4, 8, 11 } } },
  /* 11001000 */
  { 3, { { 4, 6, 8 }, { 3, 6, 4 }, { 3, 12, 6 } } },
  /* 11001001 */
  { 4, { { 6, 8, 12 }, { 8, 1, 12 }, { 1, 3, 12 }, { 9, 1, 8 } } },
  /* 11001010 */
  { 4, { { 4, 6, 8 }, { 4, 12, 6 }, { 3, 12, 4 }, { 1, 10, 2 } } },
  /* 11001011 */
  { 5, { { 3, 12, 2 }, { 9, 10, 8 }, { 8, 10, 6 }, { 6, 10, 12 }, { 12, 10, 2 } } },
  /* 11001100 */
  { 1, { { 8, 4, 2, 6 } } },
  /* 11001101 */
  { 3, { { 8, 2, 6 }, { 8, 1, 2 }, { 9, 1, 8 } } },
  /* 11001110 */
  { 3, { { 4, 6, 8 }, { 4, 10, 6 }, { 1, 10, 4 } } },
  /* 11001111 */
  { 1, { { 8, 9, 10, 6 } } },
  /* 11010000 */
  { 3, { { 12, 9, 11 }, { 6, 9, 12 }, { 6, 5, 9 } } },
  /* 11010001 */
  { 4, { { 6, 11, 12 }, { 6, 1, 11 }, { 6, 5, 1 }, { 11, 1, 4 } } },
  /* 11010010 */
  { 4, { { 12, 9, 11 }, { 12, 5, 9 }, { 6, 5, 12 }, { 2, 1, 10 } } },
  /* 11010011 */
  { 5, { { 5, 10, 6 }, { 11, 12, 4 }, { 4, 12, 2 }, { 2, 12, 10 }, { 10, 12, 6 } } },
  /* 11010100 */
  { 4, { { 9, 11, 5 }, { 11, 2, 5 }, { 2, 6, 5 }, { 3, 2, 11 } } },
  /* 11010101 */
  { 5, { { 11, 3, 4 }, { 5, 1, 6 }, { 6, 1, 2 }, { 2, 1, 3 }, { 3, 1, 4 } } },
  /* 11010110 */
  { 5, { { 6, 5, 10 }, { 3, 1, 11 }, { 11, 1, 9 }, { 9, 1, 5 }, { 5, 1, 10 } } },
  /* 11010111 */
  { 2, { { 11, 3, 4 }, { 5, 10, 6 } } },
  /* 11011000 */
  { 4, { { 12, 6, 5 }, { 3, 12, 5 }, { 9, 3, 5 }, { 4, 3, 9 } } },
  /* 11011001 */
  { 3, { { 3, 5, 1 }, { 3, 6, 5 }, { 12, 6, 3 } } },
  /* 11011010 */
  { 10, { { 3, 12, 2 }, { 4, 1, 9 }, { 5, 10, 6 }, { 10, 5, 9 }, { 10, 9, 1 }, { 1, 4, 3 }, { 1, 3, 2 }, { 10, 12, 6 }, { 10, 2, 12 }, { 10, 1, 2 } } },
  /* 11011011 */
  { 4, { { 12, 2, 3 }, { 10, 6, 5 }, { 10, 2, 12 }, { 10, 12, 6 } } },
  /* 11011100 */
  { 3, { { 6, 4, 2 }, { 6, 9, 4 }, { 5, 9, 6 } } },
  /* 11011101 */
  { 1, { { 1, 2, 6, 5 } } },
  /* 11011110 */
  { 4, { { 5, 10, 6 }, { 1, 9, 4 }, { 1, 10, 5 }, { 1, 5, 9 } } },
  /* 11011111 */
  { 1, { { 6, 5, 10 } } },
  /* 11100000 */
  { 3, { { 10, 11, 12 }, { 5, 11, 10 }, { 5, 8, 11 } } },
  /* 11100001 */
  { 4, { { 10, 11, 12 }, { 10, 8, 11 }, { 5, 8, 10 }, { 1, 4, 9 } } },
  /* 11100010 */
  { 4, { { 11, 12, 8 }, { 12, 1, 8 }, { 1, 5, 8 }, { 2, 1, 12 } } },
  /* 11100011 */
  { 5, { { 5, 8, 9 }, { 2, 4, 12 }, { 12, 4, 11 }, { 11, 4, 8 }, { 8, 4, 9 } } },
  /* 11100100 */
  { 4, { { 10, 5, 8 }, { 2, 10, 8 }, { 11, 2, 8 }, { 3, 2, 11 } } },
  /* 11100101 */
  { 10, { { 2, 10, 1 }, { 3, 4, 11 }, { 8, 9, 5 }, { 9, 8, 11 }, { 9, 11, 4 }, { 4, 3, 2 }, { 4, 2, 1 }, { 9, 10, 5 }, { 9, 1, 10 }, { 9, 4, 1 } } },
  /* 11100110 */
  { 3, { { 5, 3, 1 }, { 5, 11, 3 }, { 8, 11, 5 } } },
  /* 11100111 */
  { 4, { { 8, 9, 5 }, { 4, 11, 3 }, { 4, 9, 8 }, { 4, 8, 11 } } },
  /* 11101000 */
  { 4, { { 5, 12, 10 }, { 5, 4, 12 }, { 5, 8, 4 }, { 12, 4, 3 } } },
  /* 11101001 */
  { 5, { { 8, 9, 5 }, { 12, 10, 3 }, { 3, 10, 1 }, { 1, 10, 9 }, { 9, 10, 5 } } },
  /* 11101010 */
  { 5, { { 12, 2, 3 }, { 8, 4, 5 }, { 5, 4, 1 }, { 1, 4, 2 }, { 2, 4, 3 } } },
  /* 11101011 */
  { 2, { { 9, 5, 8 }, { 3, 12, 2 } } },
  /* 11101100 */
  { 3, { { 2, 8, 4 }, { 2, 5, 8 }, { 10, 5, 2 } } },
  /* 11101101 */
  { 4, { { 9, 5, 8 }, { 10, 1, 2 }, { 10, 5, 9 }, { 10, 9, 1 } } },
  /* 11101110 */
  { 1, { { 5, 8, 4, 1 } } },
  /* 11101111 */
  { 1, { { 9, 5, 8 } } },
  /* 11110000 */
  { 1, { { 9, 11, 12, 10 } } },
  /* 11110001 */
  { 3, { { 10, 11, 12 }, { 10, 4, 11 }, { 1, 4, 10 } } },
  /* 11110010 */
  { 3, { { 12, 9, 11 }, { 12, 1, 9 }, { 2, 1, 12 } } },
  /* 11110011 */
  { 1, { { 4, 11, 12, 2 } } },
  /* 11110100 */
  { 3, { { 11, 10, 9 }, { 11, 2, 10 }, { 3, 2, 11 } } },
  /* 11110101 */
  { 4, { { 1, 2, 10 }, { 3, 4, 11 }, { 3, 2, 1 }, { 3, 1, 4 } } },
  /* 11110110 */
  { 1, { { 1, 9, 11, 3 } } },
  /* 11110111 */
  { 1, { { 11, 3, 4 } } },
  /* 11111000 */
  { 3, { { 9, 12, 10 }, { 9, 3, 12 }, { 4, 3, 9 } } },
  /* 11111001 */
  { 1, { { 3, 12, 10, 1 } } },
  /* 11111010 */
  { 4, { { 4, 1, 9 }, { 2, 3, 12 }, { 2, 1, 4 }, { 2, 4, 3 } } },
  /* 11111011 */
  { 1, { { 2, 3, 12 } } },
  /* 11111100 */
  { 1, { { 9, 4, 2, 10 } } },
  /* 11111101 */
  { 1, { { 10, 1, 2 } } },
  /* 11111110 */
  { 1, { { 4, 1, 9 } } },
  /* 11111111 */
  { 0 },
};


/*
 * The wedge table uses all tri facets even though
 * there are places where it could use quads...
 * It looks like the wedge code was never finished -
 * CX_Wedge_Iso_Facets_Num() still uses Wayne's style
 * of code (big switch on the mask value) rather than
 * the table. Also, the wedge table index apparently
 * has node zero as the highest order bit, which is
 * the opposite of the hex table.
 */

static CELL_ENTRY wedge_table[64] =
{
  /* 0 */
  { 0 },
  /* 1 */
  { 1, { { 4, 5, 8 } } },
  /* 2 */
  { 1, { { 3, 4, 7 } } },
  /* 3 */
  { 2, { { 3, 5, 8 }, { 7, 3, 8 } } },
  /* 4 */
  { 1, { { 3, 6, 5 } } },
  /* 5 */
  { 2, { { 3, 6, 8 }, { 4, 3, 8 } } },
  /* 6 */
  { 2, { { 6, 5, 4 }, { 6, 4, 7 } } },
  /* 7 */
  { 1, { { 8, 7, 6 } } },
  /* 8 */
  { 1, { { 2, 1, 8 } } },
  /* 9 */
  { 2, { { 4, 2, 1 }, { 5, 2, 4 } } },
  /* 10 */
  { 2, { { 2, 1, 8 }, { 3, 4, 7 } } },
  /* 11 */
  { 3, { { 2, 1, 7 }, { 5, 2, 7 }, { 3, 5, 7 } } },
  /* 12 */
  { 2, { { 2, 1, 8 }, { 5, 3, 6 } } },
  /* 13 */
  { 3, { { 6, 2, 1 }, { 4, 6, 1 }, { 3, 6, 4 } } },
  /* 14 */
  { 3, { { 2, 1, 8 }, { 6, 5, 4 }, { 6, 4, 7 } } },
  /* 15 */
  { 2, { { 7, 2, 1 }, { 6, 2, 7 } } },
  /* 16 */
  { 1, { { 7, 1, 0 } } },
  /* 17 */
  { 2, { { 7, 1, 0 }, { 4, 5, 8 } } },
  /* 18 */
  { 2, { { 1, 0, 3 }, { 1, 3, 4 } } },
  /* 19 */
  { 3, { { 1, 0, 8 }, { 8, 0, 3 }, { 5, 8, 3 } } },
  /* 20 */
  { 2, { { 7, 1, 0 }, { 5, 3, 6 } } },
  /* 21 */
  { 3, { { 7, 1, 0 }, { 3, 6, 8 }, { 4, 3, 8 } } },
  /* 22 */
  { 3, { { 1, 0, 6 }, { 4, 1, 6 }, { 4, 6, 5 } } },
  /* 23 */
  { 2, { { 1, 0, 6 }, { 1, 6, 8 } } },
  /* 24 */
  { 2, { { 2, 0, 7 }, { 8, 2, 7 } } },
  /* 25 */
  { 3, { { 2, 0, 7 }, { 5, 2, 7 }, { 4, 5, 7 } } },
  /* 26 */
  { 3, { { 0, 8, 2 }, { 3, 8, 0 }, { 3, 4, 8 } } },
  /* 27 */
  { 2, { { 5, 2, 0 }, { 3, 5, 0 } } },
  /* 28 */
  { 3, { { 5, 3, 6 }, { 2, 0, 7 }, { 8, 2, 7 } } },
  /* 29 */
  { 2, { { 6, 2, 0 }, { 7, 4, 3 } } },
  /* 30 */
  { 2, { { 6, 2, 0 }, { 8, 5, 4 } } },
  /* 31 */
  { 1, { { 6, 2, 0 } } },
  /* 32 */
  { 1, { { 0, 2, 6 } } },
  /* 33 */
  { 2, { { 0, 2, 6 }, { 4, 5, 8 } } },
  /* 34 */
  { 2, { { 0, 2, 6 }, { 3, 4, 7 } } },
  /* 35 */
  { 3, { { 6, 3, 5 }, { 7, 0, 2 }, { 7, 2, 8 } } },
  /* 36 */
  { 2, { { 0, 2, 5 }, { 0, 5, 3 } } },
  /* 37 */
  { 3, { { 2, 8, 0 }, { 0, 8, 3 }, { 8, 4, 3 } } },
  /* 38 */
  { 3, { { 7, 0, 2 }, { 7, 2, 5 }, { 7, 5, 4 } } },
  /* 39 */
  { 2, { { 7, 0, 2 }, { 7, 2, 8 } } },
  /* 40 */
  { 2, { { 6, 0, 1 }, { 8, 6, 1 } } },
  /* 41 */
  { 3, { { 6, 0, 1 }, { 6, 1, 4 }, { 5, 6, 4 } } },
  /* 42 */
  { 3, { { 0, 1, 7 }, { 8, 6, 3 }, { 8, 3, 4 } } },
  /* 43 */
  { 2, { { 0, 1, 7 }, { 6, 3, 5 } } },
  /* 44 */
  { 3, { { 8, 0, 1 }, { 3, 0, 8 }, { 3, 8, 5 } } },
  /* 45 */
  { 2, { { 3, 0, 1 }, { 4, 3, 1 } } },
  /* 46 */
  { 2, { { 0, 1, 7 }, { 8, 5, 4 } } },
  /* 47 */
  { 1, { { 0, 1, 7 } } },
  /* 48 */
  { 2, { { 1, 2, 7 }, { 7, 2, 6 } } },
  /* 49 */
  { 3, { { 8, 1, 2 }, { 4, 5, 6 }, { 7, 4, 6 } } },
  /* 50 */
  { 3, { { 1, 2, 6 }, { 1, 6, 4 }, { 4, 6, 3 } } },
  /* 51 */
  { 2, { { 8, 1, 2 }, { 6, 3, 5 } } },
  /* 52 */
  { 3, { { 7, 1, 2 }, { 7, 2, 5 }, { 7, 5, 3 } } },
  /* 53 */
  { 2, { { 8, 1, 2 }, { 7, 4, 3 } } },
  /* 54 */
  { 2, { { 1, 2, 4 }, { 4, 2, 5 } } },
  /* 55 */
  { 1, { { 8, 1, 2 } } },
  /* 56 */
  { 1, { { 6, 7, 8 } } },
  /* 57 */
  { 2, { { 4, 5, 6 }, { 7, 4, 6 } } },
  /* 58 */
  { 2, { { 8, 6, 3 }, { 8, 3, 4 } } },
  /* 59 */
  { 1, { { 5, 6, 3 } } },
  /* 60 */
  { 2, { { 8, 5, 3 }, { 8, 3, 7 } } },
  /* 61 */
  { 1, { { 7, 4, 3 } } },
  /* 62 */
  { 1, { { 8, 5, 4 } } },
  /* 63 */
  { 0 }
};
